/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       global_event.h

	$Header: /game/global_event.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( GLOBAL_EVENT_H_INCLUDED )
#define GLOBAL_EVENT_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <bitset>
#include <string>

#include "continuous_event.h"
#include "player_color.h"
#include "timed_event.h"
#include "triggerable_event.h"

// --------------------------------------------------------------------------
// t_global_player_filtered_event class
// --------------------------------------------------------------------------

class t_global_player_filtered_event
{
public:
	// Types
	typedef std::bitset< k_active_player_color_count >	t_player_color_mask;

	// Member functions
	bool						get_run_for_computer_players() const;
	bool						get_run_for_human_players() const;
	t_player_color_mask const &	get_player_color_mask() const;
	bool						ownership_test(t_player const* player) const;

protected:
	// Constructors/Destructor
	t_global_player_filtered_event();
	t_global_player_filtered_event( t_global_player_filtered_event const & other );
	~t_global_player_filtered_event() {}

	// Member functions
	bool	read(
				std::streambuf &	stream,
				int					version );
	bool	read_from_map(
				std::streambuf &	stream,
				int					format_version );
	bool	write( std::streambuf & stream ) const;

private:
	// Data member
	t_player_color_mask	m_player_color_mask;
	bool				m_run_for_human_players;
	bool				m_run_for_computer_players;
};

// --------------------------------------------------------------------------
// t_global_player_filtered_event inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_global_player_filtered_event::t_global_player_filtered_event()
	:	m_run_for_human_players( true ),
		m_run_for_computer_players( true )
{
	m_player_color_mask.set();
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_player_filtered_event::get_run_for_computer_players() const
{
	return m_run_for_computer_players;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_player_filtered_event::get_run_for_human_players() const
{
	return m_run_for_human_players;
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_global_player_filtered_event::t_player_color_mask const &
t_global_player_filtered_event::get_player_color_mask() const
{
	return m_player_color_mask;
}

// --------------------------------------------------------------------------
// t_global_timed_event class
// --------------------------------------------------------------------------

class t_global_timed_event
	:	public t_timed_event,
		public t_global_player_filtered_event
{
public:
	// Member functions
	bool	read(
				std::streambuf &	stream,
				int					version );
	bool	read_from_map( std::streambuf & stream );
	bool	write( std::streambuf & stream ) const;
};

// --------------------------------------------------------------------------
// t_global_triggerable_event class
// --------------------------------------------------------------------------

class t_global_triggerable_event : public t_triggerable_event
{
public:
	// Member functions
	bool	read(
				std::streambuf &	stream,
				int					version );
	bool	read_from_map( std::streambuf & stream );
	bool	write( std::streambuf &	stream ) const;
};

// --------------------------------------------------------------------------
// t_global_triggerable_event inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_triggerable_event::read(
	std::streambuf &	stream,
	int					version )
{
	return t_triggerable_event::read( stream, version );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_triggerable_event::write(
	std::streambuf &	stream ) const
{
	return t_triggerable_event::write( stream );
}

// --------------------------------------------------------------------------
// t_global_continuous_event class
// --------------------------------------------------------------------------

class t_global_continuous_event : public t_continuous_event
{
public:
	// Member functions
	bool	read(
				std::streambuf &	stream,
				int					version );
	bool	read_from_map( std::streambuf & stream );
	bool	write( std::streambuf &	stream ) const;
};

// --------------------------------------------------------------------------
// t_global_continuous_event inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_continuous_event::read(
	std::streambuf &	stream,
	int					version )
{
	return t_continuous_event::read( stream, version );
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline bool t_global_continuous_event::write(
	std::streambuf &	stream ) const
{
	return t_continuous_event::write( stream );
}

// --------------------------------------------------------------------------
// t_global_placed_event class
// --------------------------------------------------------------------------

class t_global_placed_event
	:	public t_discrete_event,
		public t_global_player_filtered_event
{
public:
	// Member functions
	std::string const &	get_name() const;
	bool				read(
							std::streambuf &	stream,
							int					version );
	bool				read_from_map( std::streambuf & stream );
	bool				write( std::streambuf & stream ) const;

private:
	// Data members
	std::string	m_name;
};

// --------------------------------------------------------------------------
// t_global_placed_event inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline std::string const & t_global_placed_event::get_name() const
{
	return m_name;
}

#endif // !defined( GLOBAL_EVENT_H_INCLUDED )
